﻿using AutoMapper;
using MediatR;
using S.Transfer.API.Application.Command.TransferCommand;
using S.Transfer.Domain.Model;
using S.Transfer.Infrastructure.Interface.Transfer;
using System.Security.Claims;
using Yitter.IdGenerator;
using Microsoft.AspNetCore.Http;

namespace S.Transfer.API.Application.CommandHandlers.TransferCommandHandler
{
    public class TransferCreatelCommondHandler : IRequestHandler<TransferCreatelCommond, bool>,IRequestHandler<CreateTranFerCommand, int>,IRequestHandler<MyCreateTranFerCommand, int>
    {
        private readonly ITransferModellRepository transfer;
        private readonly IMapper mapper;
        public TransferCreatelCommondHandler(ITransferModellRepository _transfer, IMapper _mapper)
        {
            this.transfer = _transfer;
            this.mapper = _mapper;
        }

        public async Task<bool> Handle(TransferCreatelCommond request, CancellationToken cancellationToken)
        {
            request.DocumentNumbe=YitIdHelper.NextId();
            request.CreateDate = DateTime.Now;
            SheepRescission columns = mapper.Map<SheepRescission>(request);
            return await transfer.AddAsync(columns);
           
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Handle(CreateTranFerCommand request, CancellationToken cancellationToken)
        {
            
            return await transfer.AddTransferModelModelAsync(request.sheep);
        }
        
        public async Task<int> Handle(MyCreateTranFerCommand request, CancellationToken cancellationToken)
        {
            return await transfer.AddTransferModelModelAsync(request.sheep);
        }
    }
}
